package guda.house.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.house.biz.BillEstateBiz;
import guda.house.dal.dao.BillEstateDAO;
import guda.house.dal.dataobject.BillEstateDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class BillEstateBizImpl implements BillEstateBiz{

    private final static Logger logger = LoggerFactory.getLogger(BillEstateBizImpl.class);

    @Autowired
    private BillEstateDAO billEstateDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            BillEstateDO billEstateDO = billEstateDAO.getBillEstateById(id);
            bizResult.data.put("billEstateDO", billEstateDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query BillEstate error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = billEstateDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<BillEstateDO> billEstateList = billEstateDAO.selectForPage(baseQuery);
            bizResult.data.put("billEstateList", billEstateList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view BillEstate list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            billEstateDAO.delBillEstateById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete billEstate error", e);
        }
        return bizResult;
    }

    public BizResult create(BillEstateDO billEstateDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = billEstateDAO.insert(billEstateDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create BillEstate error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(BillEstateDO billEstateDO) {
        BizResult bizResult = new BizResult();
        try {
            billEstateDAO.updateByIdSelective(billEstateDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update BillEstate error", e);
        }
        return bizResult;
    }


}
